/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package doan.quanlycanbo.portlet.service.impl;

import java.util.List;

import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.ResourceConstants;

import doan.quanlycanbo.portlet.NoSuchhesoluongException;
import doan.quanlycanbo.portlet.model.hesoluong;
import doan.quanlycanbo.portlet.service.base.hesoluongLocalServiceBaseImpl;

/**
 *
 * @author Nguyen Tuan Vinh
 */
public class hesoluongLocalServiceImpl extends hesoluongLocalServiceBaseImpl {
	
	public List<hesoluong> getAll() throws SystemException{
		return hesoluongPersistence.findAll();
	}
	
	public List<hesoluong> getByNgachLuong(long ngachluong) throws SystemException{
		return hesoluongPersistence.findByNgachLuong(ngachluong);
	}
	
	public hesoluong addHeSoLuong(hesoluong hesoluong1, long userId) throws SystemException{
		long mahesoluong = CounterLocalServiceUtil.increment(hesoluong.class.getName());
		hesoluong hesoluong2 = hesoluongPersistence.create(mahesoluong);
		hesoluong2.setGroupId(hesoluong1.getGroupId());
		hesoluong2.setCompanyId(hesoluong1.getCompanyId());
		hesoluong2.setLanguageId(hesoluong1.getLanguageId());
		hesoluong2.setMangachluong(hesoluong1.getMangachluong());
		hesoluong2.setBacluong(hesoluong1.getBacluong());
		hesoluong2.setHesoluong(hesoluong1.getHesoluong());

		try {
			resourceLocalService.addResources(hesoluong1.getCompanyId(), hesoluong1.getGroupId(), userId, 
					hesoluong.class.getName(), hesoluong2.getPrimaryKey(), false, true, true);
		} catch (PortalException e) {
			e.printStackTrace();
		}
		
		return hesoluongPersistence.update(hesoluong2, false);
	}
	
	public hesoluong updateHeSoLuong(long mahesoluong, long maNgachLuong, double bacLuong, double heSoluong) throws SystemException, NoSuchhesoluongException{
		hesoluong hesoluong = hesoluongPersistence.findByPrimaryKey(mahesoluong);
		hesoluong.setMangachluong(maNgachLuong);
		hesoluong.setBacluong(bacLuong);
		hesoluong.setHesoluong(heSoluong);
		return hesoluongPersistence.update(hesoluong, false);
	}
	
	public hesoluong deleteHeSoLuong(long mahesoluong) throws SystemException, NoSuchhesoluongException,PortalException{
		hesoluong hesoluong = hesoluongPersistence.findByPrimaryKey(mahesoluong);
		return deleteHeSoLuong(hesoluong);
	}
	
	public hesoluong deleteHeSoLuong(hesoluong hesoluong) throws SystemException,PortalException{
		resourceLocalService.deleteResource(hesoluong.getCompanyId(), hesoluong.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, hesoluong.getPrimaryKey());
		return hesoluongPersistence.remove(hesoluong);
	}
}